package com.yunpi.integration.service.demo.transformer;

import com.google.gson.Gson;
import com.yunpi.integration.common.dto.Customer;
import com.yunpi.integration.common.dto.CustomerB;
import com.yunpi.integration.common.utils.Ret;
import org.springframework.beans.BeanUtils;
import org.springframework.integration.transformer.Transformer;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * @author 汪春
 * @title: CustomerTransformer
 * @projectName yunpi_integration_demo
 * @description: 转化数据字典以及将数值映射到不同字段
 * @date 2020/6/7 11:07
 */
public class CustomerTransformerTwo implements Transformer {

    @Override
    public Message<?> transform(Message<?> message) {
        System.out.println(message);
//        String payload = (String) message.getPayload();
//        HashMap ret = new Gson().fromJson(payload, HashMap.class);
//        Customer customer =  new Gson().fromJson(ret.get("data"), Customer.class);
//        CustomerB customerB = new CustomerB();
//        BeanUtils.copyProperties(customer, customerB);
//        // 装换男女数字字典值
//        Integer gender = customer.getGender();
//        //1: 男  2: 女
//        if(gender == 1){
//            customerB.setSex("男");
//        } else if(gender == 2){
//            customerB.setSex("女");
//        } else {
//            customerB.setSex("未知");
//        }
//        GenericMessage genericMessage = new GenericMessage(customerB, message.getHeaders());
//        System.out.println(genericMessage);
//        return genericMessage;
        return message;
    }

}
